﻿namespace Max.PH5_2103A.Shopping.Frame.IService
{

    /// <summary>
    /// 基本的CRUD服务接口
    /// </summary>
    public interface IBaseService<T> where T : class,new()
    {
        #region 添加数据

        /// <summary>
        /// 添加一条数据
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        int Insert(T t);

        /// <summary>
        /// 批量添加数据
        /// </summary>
        /// <param name="list"></param>
        /// <returns></returns>
        int Insert(List<T> list);

        #endregion

        #region 删除数据

        /// <summary>
        /// 删除一条数据
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        int Delete(T t);

        /// <summary>
        /// 批量删除数据
        /// </summary>
        /// <param name="list"></param>
        /// <returns></returns>
        int Delete(List<T> list);

        #endregion

        #region 修改数据
        /// <summary>
        /// 删除一条数据
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        int Update(T t);

        /// <summary>
        /// 批量修改数据
        /// </summary>
        /// <param name="list"></param>
        /// <returns></returns>
        int Update(List<T> list);

        #endregion

        #region 查询数据

        
        /// <summary>
        /// 查询所有数据
        /// </summary>
        /// <returns></returns>
        IQueryable<T> GetAll();

        /// <summary>
        /// 查询分页数据
        /// </summary>
        /// <param name="pageIndex">页码（第几页）</param>
        /// <param name="pageSize">页大小（每页显示几条）</param>
        /// <param name="total">总记录数</param>
        /// <returns></returns>
        IQueryable<T> GetAll(int pageIndex,int pageSize,out int total);

        /// <summary>
        /// 带条件的查询分页数据
        /// </summary>
        /// <param name="where">具体条件</param>
        /// <param name="pageIndex">页码（第几页）</param>
        /// <param name="pageSize">页大小（每页显示几条）</param>
        /// <param name="total">总记录数</param>
        /// <returns></returns>
        IQueryable<T> GetAll(Func<T, bool> where, int pageIndex, int pageSize, out int total);

        /// <summary>
        /// 带条件和排序的分页查询数据
        /// </summary>
        /// <typeparam name="TKey">排序的字段</typeparam>
        /// <param name="where">查询的条件</param>
        /// <param name="sort">排序的条件</param>
        /// <param name="isAsc">是否是升序</param>
        /// <param name="pageIndex">页码（第几页）</param>
        /// <param name="pageSize">页大小（每页显示几条）</param>
        /// <param name="total">总记录数</param>
        /// <returns></returns>
        IQueryable<T> GetAll<TKey>(Func<T, bool> where, Func<T,TKey> sort, bool isAsc, int pageIndex, int pageSize, out int total);

        /// <summary>
        /// 查询一条数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        T GetFirstById(object id);

        #endregion
    }
}